<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .box {
      width: 150px;
      height: 250px;
      background-color: aqua;
      display: none;
      position: absolute;
    }

    .box li {
      list-style: none;
      width: 150px;
      height: 62.5px;
      line-height: 62.5px;
      border-bottom: 1px solid black;
    }

    .box li:nth-of-type(4) {
      border: 0;
    }

    .box li:hover {
      background-color: #f6f6f6;
    }
  </style>
</head>

<body>
  <div class="box">
    <ul>
      <li class="copy">复制</li>
      <li class="cut">剪切</li>
      <li class="paste">粘贴</li>
      <li class="reload">刷新</li>
    </ul>

  </div>
</body>
<script>
  var box = document.querySelector('.box');

  document.oncontextmenu = function (e) {
    var e = e || window.event;

    if (e.preventDefault) {
      e.preventDefault();
    } else {
      e.returnValue = false;
    }

    if (e.button == 2) {

      var x = e.clientX;
      var y = e.clientY;
      console.log(x, y);
      box.style.top = y + 'px';
      box.style.left = x + 'px';
      box.style.display = 'block';
    }



  }

  document.onclick = function () {
    box.style.display = 'none'
  }

  box.onclick = function () {
    var e = e || window.event;
    var target = e.target || srecElement;
    // console.log('111');

    if (e.stopPropagation) {
      e.stopPropagation();
    } else {
      e.cancelBubble = true;
    }

    if (target.className == 'copy') {
      console.log('复制');
    } else if (target.className == 'cut') {
      console.log('剪切');
    } else if (target.className == 'paste') {
      console.log('粘贴');
    } else if (target.className == 'reload') {
      console.log('刷新');
    }
    // box.style.display = "none";
  }
</script>

</html>